/* ****************************************************************************
 *
 * Copyright (c) Microsoft Corporation. 
 *
 * This source code is subject to terms and conditions of the Microsoft Public License. A 
 * copy of the license can be found in the License.html file at the root of this distribution. If 
 * you cannot locate the  Microsoft Public License, please send an email to 
 * dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound 
 * by the terms of the Microsoft Public License.
 *
 * You must not remove this notice, or any other, from this software.
 *
 * THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
 * KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
 * PARTICULAR PURPOSE.
 * ***************************************************************************/




#if !defined(AFX_PGLCOORD2D_H__F37A108B_06FD_4922_8F1B_274F68F2B2EE__INCLUDED_)
#define AFX_PGLCOORD2D_H__F37A108B_06FD_4922_8F1B_274F68F2B2EE__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include <pgl/igfx/GfxInterface.h>
class CPGLArchive;

/*! \brief An Polymorphic coordinate object.

\ingroup PGLBasicGroup

A mix of world, normalized bounding box, pixel coordinate.

\image html coordinates.png "Different coordinates used in PGL"
*/
class PGLCORE_EXT_CLASS CPGLCoord2D : public CPGLNode
{
PGL_DECLARE_DYNCREATE(CPGLCoord2D);
public:
	//! Coordinates type
	static  enum ECoord2DType 
	{
		//! World coordinates (in the clipping region)
		Coord2DWorld=0, 
		//! Normalized coordinates (with regards to the region)
		Coord2DNorm=1, 
		//! Normalized clipping coordinates (with regards to the clipping region)
		Coord2DNormClip=2, 
		//! Bounding box in pixels.
		Coord2DBB=3
	};
public:
	//! \name Constructors
	//@{
	//! Default contscrutor
	CPGLCoord2D(double _x = 0, double _y = 0, ECoord2DType eType = Coord2DWorld);
	//! Copy constructor
	CPGLCoord2D(const CPGLCoord2D& c){	*this = c;};
	//! Assignement constructor
	CPGLCoord2D& operator = (const CPGLCoord2D& c);
	//! Desctructor
	virtual ~CPGLCoord2D();
	//@}
	
	//! \name Getters for position
	//@{
	//! returns current coordinate in client coordinates
	gfxinterface::SPointD			GetScreenPosition(const gfxinterface::CGfxInterface& gfx) const;
	//! returns current coordinate in current world coordinates
	gfxinterface::SPointD			GetWorldPosition(const gfxinterface::CGfxInterface& gfx) const;
	//! returns current position in the specified domain
	const gfxinterface::SPointD&	GetPosition() const { return m_sPos;};
	//@}

	//! \name Setters for position
	//@{
	//! Set the anchor position using SPointD structure 
	void SetPosition(const gfxinterface::SPointD& pos, ECoord2DType type = Coord2DWorld)	{	m_ePosType = type; m_sPos=pos;};
	//! Sets the anchor position
	void SetPosition(double x, double y, ECoord2DType type = Coord2DWorld)	{	m_ePosType = type; m_sPos.x=x; m_sPos.y=y;};
	//! Sets the translation to make in world coordinate
	void SetWorldTrans(const gfxinterface::SPointD& trans)		{	m_sWorldTrans = trans;};
	//! Sets the translation to make in normalized coordinate
	void SetNormTrans(const gfxinterface::SPointD& trans)		{	m_sNormTrans = trans;};
	//! Sets the translation to make in normalized clipping coordinate
	void SetNormClipTrans(const gfxinterface::SPointD& trans)	{	m_sNormClipTrans = trans;};
	//! Sets the translation to make in screen coordinates (pixels)
	void SetBBTrans(const gfxinterface::SPointD& trans)			{	m_sBBTrans = trans;};
	//! Clear all translations
	void ClearTrans()	
	{	memset(&m_sWorldTrans,0,sizeof(gfxinterface::SPointD));
		memset(&m_sNormTrans,0,sizeof(gfxinterface::SPointD));
		memset(&m_sNormClipTrans,0,sizeof(gfxinterface::SPointD));
		memset(&m_sBBTrans,0,sizeof(gfxinterface::SPointD));};
	//@}

	//! \name Serialization and debugging
	//@{
	void SerializeXML( CPGLArchive& ar);
	//! Converts ECoord2DType enum to string
	static CString Coord2DTypeToString(ECoord2DType eCoord2DType);
	//! Converts string to ECoord2DType 
	static ECoord2DType StringToCoord2DType(LPCTSTR szCoord2DType);

	#ifdef _DEBUG
	    virtual void Dump( CDumpContext& dc ) const;
	    virtual void AssertValid() const;    // Override
	#endif
	//@}

private:
	//! \name Attributes
	//@{
	//! Current anchor position
	gfxinterface::SPointD m_sPos;
	//! Type of coordinates for anchor position
	ECoord2DType m_ePosType;
	//! World translation
	gfxinterface::SPointD m_sWorldTrans;
	//! Normalized coordinates translation
	gfxinterface::SPointD m_sNormTrans;
	//! Normalized clipping coordinates translation
	gfxinterface::SPointD m_sNormClipTrans;
	//! Pixels translation
	gfxinterface::SPointD m_sBBTrans;
	//@}
};

#endif // !defined(AFX_PGLCOORD2D_H__F37A108B_06FD_4922_8F1B_274F68F2B2EE__INCLUDED_)
